package com.woniuxy.config;


import com.woniuxy.utils.StringToDate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author 罗蔚
 * @Date 2022/4/7 21:13
 * @Description TODO
 */
@Configuration
public class MyConverter implements WebMvcConfigurer {

    //<bean id=“string2DateConverter 方法名” class=“com.woniuxy.utils.String2DateConverter”/>
    //注册成bean 还不够，还需要把这个bean对象注入到springmvc流程中/
    //<bean id="conversionServiceFactoryBean" class="org.springframework.context.support.ConversionServiceFactoryBean">
    //        <property name="converters">
    //            <set>
    //                &lt;!&ndash;            自定义的类型转换器！    &ndash;&gt;
    //                <bean class="com.woniuxy.utils.StringToDate"/>
    //            </set>
    //        </property>
    //    </bean>
    @Bean
    public StringToDate stringToDate(){
        return new StringToDate();
    }
    //注册到SpringMVC环境中
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(stringToDate());
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //设置欢迎页面 thymeleaf 底层设置了视图解析器的前缀/templates和后缀.html
        registry.addViewController("/").setViewName("index");
        //设置生效的优先级
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}
